package org.starlight.delete;

import org.springframework.stereotype.Component;
import org.starlight.delete.enums.TableEnum;
import org.starlight.infrastructure.util.jackson.JacksonUtil;

/**
 * @author huangyong
 * @data 2025/2/28
 */
@Component
public class DeleteRecordHelper {

    private static DeleteRecordRepository deleteRecordRepository;

    public DeleteRecordHelper(DeleteRecordRepository deleteRecordRepositoryArg) {
        deleteRecordRepository = deleteRecordRepositoryArg;
    }


    public static void saveDeleteRecord(TableEnum table, Object obj) {
        if (obj == null) {
            return;
        }
        String json = obj instanceof String ? String.valueOf(obj) : JacksonUtil.toJson(obj);
        DeleteRecord record = new DeleteRecord();
        record.setTableName(table.name());
        record.setRecord(json);
        deleteRecordRepository.save(record);
    }
}
